package controller

import (
	"github.com/gofiber/fiber/v2"
	"guns-excel/internal/app/model"
	"guns-excel/internal/app/service"
	"guns-excel/internal/pkg/util/result"
)

// 新增模型
func AddModel(ctx *fiber.Ctx) error {
	model := new(model.Model)
	if err := ctx.BodyParser(model); err != nil {
		return ctx.JSON(result.Err.WithMsg("解析参数出错，请检查传参"))
	}
	if err := service.AddModel(ctx, model); err != nil {
		return ctx.JSON(result.Err.WithMsg("新增失败"))
	}
	return ctx.JSON(result.OK)
}

// 获取模型tree
func GetModelTree(ctx *fiber.Ctx) error {
	treeModel, err := service.GetModelTree(ctx)
	if err != nil {
		return ctx.JSON(result.Err.WithMsg("获取失败"))
	}
	return ctx.JSON(result.OK.WithData(treeModel))
}
